package com.swt.gap.controller;

import com.swt.gap.common.graph.Graph;
import com.swt.gap.model.vo.EventExtractVO;
import com.swt.gap.model.vo.element.ElementParseVO;
import com.swt.gap.service.FileService;
import com.swt.gap.service.TextDataService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 请填写说明
 *
 * @author sx
 * @date 2020/9/4 10:03
 */
@Api(tags = "文本提取")
@RestController
@RequestMapping("/text-data")
@Slf4j
public class TextDataController {

    private final TextDataService textDataService;
    private final FileService fileService;

    public TextDataController(TextDataService textDataService, FileService fileService) {
        this.textDataService = textDataService;
        this.fileService = fileService;
    }

    @PostMapping("/event-element")
    @ApiOperation(value = "要素提取,提取事件要素", notes = "要素提取,提取事件要素")
    @ApiImplicitParam(name = "text", dataType = "String",paramType = "body", value = "待提取文本")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = ElementParseVO.class)})
    public ResponseEntity<ElementParseVO> extractAndParse(@RequestBody String text){
        return ResponseEntity.ok(textDataService.extractCombinedEvents(text));
    }

    @PostMapping("/text-graph")
    @ApiOperation(value = "图谱展示", notes = "图谱展示")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "eventExtracts", dataType = "array",paramType = "body", value = "提取的事件内容"),
            @ApiImplicitParam(name = "savedFileName", dataType = "String",paramType = "query", value = "提取内容文件名")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = Graph.class)})
    public ResponseEntity<Graph> parseGraph(@RequestBody List<ElementParseVO.EventExtractVO> eventExtracts, @RequestParam String savedFileName){
        return ResponseEntity.ok(textDataService.generateGraph(eventExtracts, savedFileName));
    }

    @PostMapping("/general-element")
    @ApiOperation(value = "通用要素提取", notes = "通用要素提取")
    @ApiImplicitParam(name = "text", dataType = "String",paramType = "body", value = "待提取文本")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = EventExtractVO.class)})
    public ResponseEntity<EventExtractVO> parseElement(@RequestBody String text){
        return ResponseEntity.ok(fileService.parseElement(null, text));
    }
    @PostMapping("/general-element-v2")
    @ApiOperation(value = "通用要素提取v2", notes = "通用要素提取v2")
    @ApiImplicitParam(name = "text", dataType = "String",paramType = "body", value = "待提取文本")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = EventExtractVO.class)})
    public ResponseEntity<EventExtractVO> parseElementNew(@RequestBody String text){
        return ResponseEntity.ok(fileService.parseElementNew(null, text));
    }
}
